import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
  state:{
    name:'vicky',
    age:18
  },
  getters:{
    nameinfo(state,getters){
      return '姓名：'+state.name
    },
    fullinfo(state,getters){
      return getters.nameinfo+'；年纪：'+state.age
    },
  },
  mutations:{
    edit(state,payload){
       payload.name?state.name =payload.name:'';
       payload.age?state.age =payload.age:'';
    }
  },
  actions:{
    aedit(context,payload){
      return new Promise((resolve,reject)=>{
        setTimeout(()=>{
            context.commit('edit',payload)
            resolve()
        },2000)
      })
    }
  }
})
export default store
// state 存放状态
// mutations state成员操作
// getters 加工state成员给外界
// actions 异步操作
// modules 模块化状态管理
